package br.edu.unifei.cct720.alieninvasion.entity.ship;

import br.edu.unifei.cct720.alieninvasion.entity.Entity;
import br.edu.unifei.cct720.alieninvasion.main.gui.GameCanvas;

/**
 * Class to represent an entity of a shot fired by the player's ship
 * 
 * @author Felipe Knappe
 */
public class ShipShotEntity extends Entity {
	
	/**
	 * The vertical speed at which the players shot moves
	 */
	private double moveSpeed = -300;
	
	/**
	 * True if this shot has been "used", its hit something
	 */
	private boolean used = false;
	
	/**
	 * Class Constructor
	 * 
	 * Create a new shot from the player
	 * 
	 * @param game The game in which the shot has been created
	 * @param ref The refence to the sprite representative of this entity
	 * @param x The initial x-coordinate of the entity
	 * @param y The initial y-coordinate of the entity
	 * 
	 */
	public ShipShotEntity(GameCanvas game, String ref, int x, int y) {
		super(game, ref, x, y);
		dy = moveSpeed;
	}

	/**
	 * Method responsible for request that this entity move 
	 * itself based on time elapsed.
	 * 
	 * @param delta The entity shift value
	 * 
	 */
	public void move(long delta) {
		// proceed with normal move
		super.move(delta);
		
		// if shot off the screen, remove the entity
		if (y < 0) {
			game.removeEntity(this);
		}
	}
	
	/**
	 * Method responsible to notify this entity that it has collided with 
	 * another entity.
	 * 
	 * @param other The other entity with which we've collided
	 * 
	 */
	public void collidedWith(Entity other) {
		/*
		 * To prevent double kills, if shot already hit something,
		 * it doesn't collide with anything else
		 */
		game.removeEntity(this);
	}
}